package com.ljxt.dt.web.servlet.storemanagementservlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljxt.dt.domain.GoodsInfo;
import com.ljxt.dt.service.storemanagementservice.AddReceptService;
import com.ljxt.dt.service.storemanagementservice.impl.AddReceptServiceImpl;
import com.ljxt.dt.vo.JsonResult;
import com.ljxt.dt.vo.storemanagement.GoodsInfoVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**用于增加页面的ajax请求
 * @author 唐春劲
 * @version 1.0.0
 * @date 2020-05-15 11:06
 * @copyright 老九学堂
 */

@WebServlet("/selectInfo")
public class SelectAddInfoServlet extends HttpServlet {
    AddReceptService admin = new AddReceptServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //得到前端页面传入进来的数组,查询数据库里面的商品信息

        String[]  strs = req.getParameterValues("goodsInfo");

        List<GoodsInfoVO> goodsInfos = admin.selectGoodsInfo(strs) ;

        //将得到的数据返回
        ObjectMapper objectMapper = new ObjectMapper();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(goodsInfos);
        resp.getWriter().write(objectMapper.writeValueAsString(jsonResult));


    }
}
